package com.guli.order.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.guli.order.entity.OrderItemEntity;
import com.guli.order.service.OrderItemService;

import com.guli.common.utils.R;


/**
 * 订单项信息
 *
 * @author 罗俊华
 * @email 1007052116@qq.com
 * @date 2020-11-19 17:11:21
 */
@RestController
@RequestMapping("/order/orderitem")
public class OrderItemController {

    @Autowired
    private OrderItemService orderItemService;


    @GetMapping("/list/{currentPage}/{size}")
    @ApiOperation("根据当前页和每页显示的记录数来获取orderItem分页列表")
    public R list(@PathVariable("currentPage") Integer currentPage, @PathVariable("size") Integer size, @RequestParam Map<String, Object> params) {

        Page<OrderItemEntity> page = orderItemService.queryPage(currentPage, size, params);

        return R.ok().put("page", page);
    }


    @GetMapping("/info/{id}")
    @ApiOperation("根据id获取OrderItem")
    public R info(@PathVariable("id") Long id) {

        OrderItemEntity orderItem = orderItemService.getById(id);

        return R.ok().put("orderItem", orderItem);
    }

    @PostMapping("/save")
    @ApiOperation("插入OrderItem")
    public R save(@RequestBody OrderItemEntity orderItem) {

        orderItemService.save(orderItem);

        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("根据id更新OrderItem")
    public R update(@RequestBody OrderItemEntity orderItem) {
            orderItemService.updateById(orderItem);

        return R.ok();
    }

    @PutMapping("/deleteBatch")
    @ApiOperation("根据id批量删除OrderItem")
    public R delete(@RequestBody Long[] ids) {
            orderItemService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
